// pages/view-detail/index.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    travelslist: null,
    hongbaotext: '',
    imgpath: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var page = this
    page.setData({
      imgpath: app.data.imgpath
    })
    app.util.request({
      url: 'entry/wxapp/gettravels',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {
        openid: app.openid
      },
      success: function (res) {
        wx.hideLoading()
        console.log(res.data)
        if (res.data.code == 200) {
          page.setData({
            travelslist: res.data.data
          })
        } else {
          wx.showToast({
            title: '没有数据！',
            icon: 'none',
            duration: 2000,
            mask: true
          })
        }
      },
      fail: function () {
        wx.hideLoading()
      }
    })
    app.util.request({
      url: 'entry/wxapp/Gethobao',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {},
      success: function (res) {
        wx.hideLoading()
        console.log(res.data)
        var hongbaotext = ''
        var hongbao = res.data.data
        if (res.data.code == 200) {
          for (var i = 0; i < hongbao.length; i++) {
            hongbaotext +=
              hongbao[i]['nickname'] +
              '获得：' +
              hongbao[i]['money'] +
              '块钱红包！     '
          }
          page.setData({
            hongbaotext: hongbaotext
          })
        }
      },
      fail: function () {
        wx.hideLoading()
      }
    })

    //console.log(JSON.parse(info));
  },

  gotravels: function () {
    wx.navigateTo({
      url: '../travels/travels'
    })
  },

  gotravelsdetaile: function (e) {
    let page = this
    console.log(e.currentTarget.dataset.id)
    app.util.request({
      url: 'entry/wxapp/Gethobao',
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      data: {},
      success: function (res) {
        wx.hideLoading()
        console.log(res.data)
        var hongbaotext = ''
        var hongbao = res.data.data
        if (res.data.code == 200) {
          for (var i = 0; i < hongbao.length; i++) {
            hongbaotext +=
              hongbao[i]['nickname'] +
              '获得：' +
              hongbao[i]['money'] +
              '块钱红包！     '
          }
          page.setData({
            hongbaotext: hongbaotext
          })
        } else {
          wx.showToast({
            title: '请求错误！',
            icon: 'none',
            duration: 2000,
            mask: true
          })
        }
      },
      fail: function () {
        wx.hideLoading()
      }
    })
    wx.navigateTo({
      url:
        '../travels-detailed/travels-detailed?id=' + e.currentTarget.dataset.id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () { }
})
